package com.chahu.service.impl;

import com.chahu.entity.Order;
import com.chahu.mapper.PurchaseMapper;
import com.chahu.service.PurchaseService;
import com.chahu.utils.MybatisUtil;
import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.session.SqlSession;

public class PurchaseServiceImpl implements PurchaseService {

    @Override
    public boolean order(Order order) {
        try (SqlSession sqlSession = MybatisUtil.getFactory().openSession(true)) {
            PurchaseMapper mapper = sqlSession.getMapper(PurchaseMapper.class);
            try {
                mapper.insertOrder(order);
            } catch (PersistenceException e) {
                System.out.println("插入失败，异常信息：" + e.getMessage());
                return false;
            }
        }
        return true;
    }
}
